import sys, os

from selenium.webdriver.common.by import By

sys.path.append(os.getcwd())

from base.base_action import BaseAction







class SetPage(BaseAction):
    # 设置页面

    # title id = com.chebao:id/title
    set_page_title = By.ID, "com.chebao:id/title"

    # 返回 xpath = android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout
    set_return_button = By.XPATH, "android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout"

    # 实名制 id = com.chebao:id/certification_rl
    set_page_relaname = By.ID, "com.chebao:id/certification_rl"

    # 银行卡认证
    set_page_bankcard = By.ID, "com.chebao:id/bank_rl"

    # 登录密码 id = com.chebao:id/changer_pwd_to_rl
    set_page_pwd = By.ID, "com.chebao:id/changer_pwd_to_rl"

    # 交易密码
    set_page_paypwd = By.ID, "com.chebao:id/chager_payword_to_rl"

    # 手势密码开关 id = com.chebao:id/gesture_switch
    set_page_gestureswitch = By.ID, "com.chebao:id/gesture_switch"

    # 修改手势密码 id = com.chebao:id/gesture_rl
    set_page_gesturepwd = By.ID, "com.chebao:id/gesture_rl"

    # 获取当前版本号  id = "com.chebao:id/version"
    set_page_vnum = By.ID, "com.chebao:id/version"

    # 清除缓存 id = com.chebao:id/clearmmmm
    set_page_clear = By.ID, "com.chebao:id/clearmmmm"

    # 立即退出 id = "com.chebao:id/exit"
    set_page_logout = By.ID, "com.chebao:id/exit"

    def get_set_page_title(self):
        # 1、获取页面title
        title = self.find_element(self.set_page_title)
        return title.text

    def click_set_return_button(self):
        # 2、点击返回按钮
        self.act_click(self.set_return_button)

    def click_set_page_relaname(self):
        # 3、点击实名制
        self.act_click(self.set_page_relaname)

    def click_set_page_bankcard(self):
        # 4、点击银行卡认证
        self.act_click(self.set_page_bankcard)

    def click_set_page_pwd(self):
        # 5、点击修改登录密码
        self.act_click(self.set_page_pwd)

    def click_set_page_paypwd(self):
        # 6、点击修改交易密码
        self.act_click(self.set_page_paypwd)

    def get_set_page_onoff(self):
        # 获取当前手势密码的开启状态
        text = self.find_element(self.set_page_gestureswitch)
        return text.text

    def click_set_page_gestureswitch(self):
        # 7、点击打开手势密码
        # 获取点击前的状态
        print(self.get_set_page_onoff())
        self.act_click(self.set_page_gestureswitch)
        # 获取点击后的状态
        print(self.get_set_page_onoff())

    def click_set_page_gesturepwd(self):
        # 8、点击设置手势密码
        self.act_click(self.set_page_gesturepwd)

    def get_set_page_vnum(self):
        # 9、获取当前版本号
        version = self.find_element(self.set_page_vnum)
        return version.text

    def click_set_page_clear(self):
        # 10、点击清除缓存
        self.act_click(self.set_page_clear)

    def click_set_page_logout(self):
        # 11、立即退出
        self.act_click(self.set_page_logout)